Communication method, device and equipment based on near field communication controller interface protocol stack

The NCI protocol stack with a core layer and operating system abstraction layer addresses the challenge of cross-platform compatibility, reducing adaptation and maintenance costs by allowing a single adaptation layer for different operating systems, thereby improving portability and efficiency.

CN120321615APending Publication Date: 2025-07-15BEIJING TSINGTENG MICROSYSTEM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510462918.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-14
Publication Date
2025-07-15

AI Technical Summary

Technical Problem

The existing NCI protocol stack can only run on Android systems and cannot be adapted on other operating systems. The adaptation and maintenance workload is large.

Method used

The architecture-level design of the NCI protocol stack includes the NCI core layer and the operating system abstraction layer. It provides multiple first-class APIs through the operating system abstraction layer to block operating system differences and enable the core layer to be shared on different operating systems. Only one adapter layer is required to adapt to the new operating system.

Benefits of technology

It effectively reduces the adaptation and maintenance costs of multiple operating systems, and improves the portability and development efficiency of the NCI protocol stack.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120321615A_ABST
    Figure CN120321615A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of NFC, and particularly provides a communication method, device and equipment based on a near field communication controller interface protocol stack, the NCI protocol stack comprises an NCI core layer and an operating system abstraction layer, the operating system abstraction layer comprises a plurality of first-class APIs, and different first-class APIs correspond to different functions related to an operating system; receiving a processing request sent by the NFC application through the NCI core layer; and by calling a first type of API corresponding to the data processing request in the abstraction layer of the operating system, sending the processing request to the operating system, so that the operating system processes the processing request. According to the embodiment of the invention, the adaptation problem of the NCI protocol stack to the multiple operating systems is solved on the architecture level, only one adaptation layer needs to be adapted when a new operating system is adapted, the core logic of the CNI protocol stack can be shared on all the operating systems, and the adaptation and maintenance cost of the multiple operating systems can be effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of Near Field Communication (NFC), and particularly to a communication method, apparatus, and device based on a Near Field Communication controller interface protocol stack. Background Art

[0002] The NFC Controller Interface (NCI) defines the way for the host system to communicate with the NFC device (NFC Controller, NFCC). The host system controls the NFC device by sending NCI commands according to the NCI protocol specification to implement NFC-related functions. Therefore, both the NFC device and the host system need to have modules or code for processing the NCI protocol. The NCI protocol processing module deployed in the host system is generally called the NCI protocol stack.

[0003] The currently widely used NCI protocol stack is the NCI protocol stack running on the Android system, which can well implement the NCI protocol functions. However, since this NCI protocol stack uses many specific interfaces and features of the Android system, this NCI protocol stack can only run on the Android system and cannot run on other operating systems.

[0004] When the existing NCI protocol stack adapts to other operating systems, a large amount of manpower is required for reconstruction, and the reconstructed code and the Android code can only be maintained separately, which will greatly increase the workload of adaptation and maintenance. Summary of the Invention

[0005] To solve the above technical problems, this application provides a communication method, apparatus, and device based on a Near Field Communication controller interface protocol stack, which solves the problem of adapting the NCI protocol stack to multiple operating systems at the architecture level. When adapting to a new operating system, only one adaptation layer needs to be adapted, and the core logic of the NCI protocol stack can be shared on all operating systems, which can effectively reduce the adaptation and maintenance costs for multiple operating systems.

[0006] In a first aspect, the present application provides a communication method based on a Near Field Communication (NFC) Controller Interface (NCI) protocol stack. The NCI protocol stack includes an NCI core layer and an operating system abstraction layer. The operating system abstraction layer includes multiple first-class Application Programming Interfaces (APIs), and different first-class APIs correspond to different functions related to the operating system. The method includes: receiving, through the NCI core layer, a processing request sent by an NFC application; and sending, by invoking a first-class API corresponding to the data processing request in the operating system abstraction layer, the processing request to the operating system so that the operating system processes the processing request.

[0007] In a second aspect, the present application provides a communication device based on a Near Field Communication (NFC) Controller Interface (NCI) protocol stack. The NCI protocol stack includes an NCI core layer and an operating system abstraction layer. The operating system abstraction layer includes multiple first-class Application Programming Interfaces (APIs), and different first-class APIs correspond to different functions related to the operating system. The device includes: a first receiving module, configured to receive, through the NCI core layer, a processing request sent by an NFC application; and a first sending module, configured to send, by invoking a first-class API corresponding to the data processing request in the operating system abstraction layer, the processing request to the operating system so that the operating system processes the processing request.

[0008] In a third aspect, the present application provides a communication device based on a Near Field Communication (NFC) Controller Interface (NCI) protocol stack. The device includes: one or more processors; and a storage device, configured to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the communication method based on the Near Field Communication (NFC) Controller Interface (NCI) protocol stack as described in the first aspect above.

[0009] In a fourth aspect, the present application provides a storage medium, which may be a computer-readable storage medium, storing a computer program thereon. When the program is executed by a processor, it implements the communication method based on the Near Field Communication (NFC) Controller Interface (NCI) protocol stack as described in the first aspect above.

[0010] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program or instruction. When the computer program or instruction is executed by a processor, it implements the communication method based on the Near Field Communication (NFC) Controller Interface (NCI) protocol stack as described in any item of the first aspect above.

[0011] The technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:

[0012] An embodiment of the present application provides a communication method, apparatus, device, and storage medium based on a Near Field Communication Controller Interface protocol stack. The NCI protocol stack includes an NCI core layer and an operating system abstraction layer. The operating system abstraction layer includes multiple first-class APIs, and different first-class APIs correspond to different operating system-related functions. Receive a processing request sent by an NFC application through the NCI core layer; send the processing request to the operating system by calling the first-class API corresponding to the data processing request in the operating system abstraction layer, so that the operating system processes the processing request. At the architecture level, the problem of adapting the NCI protocol stack to multiple operating systems is solved. Only one adaptation layer needs to be adapted for a new operating system, and the core logic of the protocol stack can be shared on all operating systems. It can effectively reduce the adaptation and maintenance costs for multiple operating systems. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application and used together with the specification to explain the principles of the present application.

[0014] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.

[0015] Figure 1 It is a schematic structural diagram of an NCI protocol stack provided by an embodiment of the present application;

[0016] Figure 2 It is a schematic flow diagram of a communication method based on the NCI protocol stack provided by an embodiment of the present application;

[0017] Figure 3 It is another schematic structural diagram of an NCI protocol stack provided by an embodiment of the present application;

[0018] Figure 4 It is still another schematic structural diagram of an NCI protocol stack provided by an embodiment of the present application;

[0019] Figure 5 It is yet another schematic structural diagram of an NCI protocol stack provided by an embodiment of the present application;

[0020] Figure 6 It is a schematic structural diagram of a communication device based on the NCI protocol stack provided by an embodiment of the present application;

[0021] Figure 7 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0022] In order to more clearly understand the above-mentioned objects, features, and advantages of the present application, the solutions of the present application will be further described below. It should be noted that, without conflict, the embodiments of the present application and the features in the embodiments may be combined with each other.

[0023] In the following description, many specific details are set forth in order to provide a thorough understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only a part of the embodiments of the present application, rather than all the embodiments.

[0024] The term "including" and its variations used herein are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0025] It should be noted that the concepts such as "first" and "second" mentioned in the present application are only used to distinguish different devices, modules, or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules, or units.

[0026] It should be noted that the modifications of "one" and "multiple" mentioned in the present application are illustrative rather than restrictive. Those skilled in the art should understand that, unless clearly stated otherwise in the context, it should be understood as "one or more".

[0027] The following will, in conjunction with the accompanying drawings and specific implementation manners, provide a detailed description of the communication method based on the near field communication controller interface protocol stack provided by the embodiments of the present application.

[0028] Figure 1 It is a schematic structural diagram of an NCI protocol stack provided by an embodiment of the present application; as Figure 1 shown, the NCI protocol stack provided by the embodiment of the present application includes an NCI core layer 11 and an operating system abstraction layer (Operation System Abstract Layer, OSAL) 12.

[0029] Among them, the NCI core layer 11 can be understood as the core layer of the NCI protocol stack, which is used to process the core functions and services of the interaction between NFC devices. The NCI core layer usually includes the functions defined by the complete NCI protocol. The NFC protocol defined in the NCI core layer is independent of the characteristics of the operating system and can be independently implemented without relying on any operating system and can run seamlessly on any operating system.

[0030] The operating system abstraction layer 12 is mainly used to shield the characteristics of the operating system from the core layer of the NCI protocol stack. In other words, the operating system abstraction layer 12 is mainly used to isolate the core layer of the NCI protocol stack from the characteristics and implementation details of the operating system layer 13. The operating system abstraction layer 12 provides a set of standardized operating system interfaces for the NCI protocol stack, enabling the core layer of the NCI protocol stack to run on different operating systems without modifying the core code in the NCI core layer. This allows the core layer of the NCI protocol stack to not have to concern itself with the specific implementation of the underlying operating system, thus achieving cross-operating system compatibility and flexibility.

[0031] The operating system abstraction layer 12 includes multiple first-class APIs, and different first-class APIs correspond to different operating system-related functions.

[0032] First-class APIs refer to interfaces that directly interact with operating system services. First-class APIs typically cover core functions such as memory management, thread management, synchronization mechanisms (such as mutexes and semaphores), timer operations, and file system access. By defining such a set of unified APIs, it can be ensured that the NCI core layer does not need to concern itself with the specific implementation details of the operating system and does not need to adjust the code according to different operating systems.

[0033] Different first-class APIs correspond to different operating system-related functions, which means that each first-class API is designed for a specific operating system function or service. For example, one API may be used to create and manage threads, another API may be used to handle inter-process communication (IPC), and yet another API may be used to set and use timers.

[0034] Since the native APIs and services provided by different operating systems may vary greatly, the operating system abstraction layer 12 abstracts the differences in the native APIs and services provided by different operating systems by providing multiple first-class APIs, making the native APIs and services provided by different operating systems appear the same to the NCI core layer.

[0035] Specifically, since the operating system abstraction layer 12 is responsible for mapping the calls of the core layer of the NCI protocol stack to the corresponding services provided by the current operating system. For example, if the core layer of the NCI protocol stack needs to create a new thread, the core layer of the NCI protocol stack only needs to call the thread creation API provided by the operating system abstraction layer 12 without concerning itself with the specific implementation method of this API on Linux, Windows, or other operating systems.

[0036] Exemplarily, such as Figure 1As shown, the operating system abstraction layer provides a set of standardized APIs that allow the protocol stack to access underlying services in an operating system-independent manner. The operating system abstraction layer specifically includes the following modules: The Android module is the abstraction layer implementation for the Android operating system. The HarmonyOS (OHOS) module is the abstraction layer implementation for the HarmonyOS operating system. The Linux module is the abstraction layer implementation for the Linux operating system. The RTOS module is the abstraction layer implementation for the Real Time Operate System (RTOS).

[0037] The operating system module 13 is the specific implementation of the underlying operating system code, including the Hardware Abstraction Layer (HAL) and other operating system kernel components. It specifically includes the following parts: The Android HAL module is the hardware abstraction layer of the Android operating system, providing an access interface to hardware devices. The OHOS HAL module is the hardware abstraction layer of the OHOS operating system, providing an access interface to hardware devices. The Linux Kernel is the kernel of the Linux operating system, responsible for managing hardware resources and providing basic operating system services. The RTOS hardware is the hardware-related components of the real-time operating system, which may include specific drivers and hardware configurations.

[0038] By using multiple first-class APIs, the core layer of the NCI protocol stack can run on different operating systems without modifying the core code, effectively reducing the adaptation and maintenance costs for multiple operating systems and greatly improving the portability and development efficiency of the NCI protocol stack.

[0039] In a possible implementation, the functions related to the operating system include at least one of the following: locks, threads, logging, input / output, and NCI instructions.

[0040] Locks are used to synchronize access to shared resources and avoid data competition problems in a concurrent environment. Locks include but are not limited to mechanisms such as mutex locks and read-write locks.

[0041] In the embodiments of this application, through the unified lock-related APIs provided by the operating system abstraction layer 12, developers can use locks to protect critical sections without considering the differences of specific operating systems.

[0042] Thread management is the basis of multitasking, involving functions such as thread creation, start, pause, resume, and destruction. The thread-related APIs provided by the operating system abstraction layer 12 allow the NCI core layer to manage threads consistently on different operating systems, thus simplifying cross-platform development.

[0043] Logging is crucial for debugging and monitoring system behavior. The operating system abstraction layer 12 can provide a unified logging API, which may map to different logging services or tools on different operating systems, but for the NCI core layer, its interface remains consistent.

[0044] Input / output involves various types of input / output operations such as file system access, network communication, and device driver interaction. The input / output API provided by the operating system abstraction layer 12 allows the NCI core layer to perform operations such as opening files, reading / writing data, and sending / receiving network packets without directly depending on the I / O functions of a specific operating system.

[0045] For NCI instructions related to NFC technology, the operating system abstraction layer 12 also provides an API for processing NCI instructions. This API is responsible for parsing and generating NCI commands and responses and managing the communication process between NFC devices. Through this layer of abstraction, the compatibility and consistency of the core layer of the NCI protocol stack on different operating systems can be ensured.

[0046] Furthermore, the development language in the NCI core layer is C language to further ensure that the code in the NCI core layer can be compiled and run on any operating system. The operating system abstraction layer 12 can choose a mainstream development language, which is not specifically limited in the embodiments of this application.

[0047] Figure 2 This is a flowchart of a communication method based on the Near Field Communication Controller Interface Protocol Stack in the embodiments of this application, as Figure 2 shown, the communication method based on the Near Field Communication Controller Interface Protocol Stack provided by the embodiments of this application mainly includes steps S101 - S102.

[0048] S101, receive a processing request sent by an NFC application through the NCI core layer.

[0049] Among them, the NFC application refers to a software application that uses NFC technology to implement specific functions or services. NFC is a short - range high - frequency wireless communication technology that allows simple and secure two - way communication between electronic devices. NFC technology is usually used on smartphones, tablets, and other portable devices to support various application scenarios, including but not limited to: mobile payment, data exchange, smart tag reading and writing, access control, transportation cards and tickets, etc.

[0050] The processing request sent by the NFC application refers to an instruction or request sent by an NFC - related application program running on the device to the NCI core layer. This processing request includes but is not limited to: querying the NFC status, starting the NFC discovery mode, sending specific data packets, etc.

[0051] The NCI core layer receives a specific operation request from the NFC application and forwards the request to the operating system for execution.

[0052] Specifically, the NFC application determines when and how to use the NFC function according to its business logic. For example, when the user wants to make a payment via the mobile phone, the payment application generates a corresponding processing request. This processing request is then sent to the NCI core layer. After receiving the processing request, the NCI core layer first parses it to determine the specific content and purpose of the request. Based on the parsing result, the NCI core layer prepares the corresponding commands or instruction sets and passes them to the underlying hardware through the operating system abstraction layer.

[0053] S102. Send the processing request to the operating system by calling the first type of API in the operating system abstraction layer corresponding to the data processing request, so that the operating system processes the processing request.

[0054] Specifically, the NCI core layer receives a data processing request from the NFC application. For example, a request to start the NFC discovery mode, or a request to read NFC tag information.

[0055] According to the specific type of the request, the NCI core layer determines which first type of API provided by the operating system abstraction layer needs to be called. For example, if the request involves data transmission, an API related to I / O operations may be selected; if it is about synchronization issues, an API related to the lock mechanism may be involved.

[0056] Then, the NCI core layer passes the processing request to the operating system by calling the appropriate first type of API provided by the operating system abstraction layer. Due to the existence of the operating system abstraction layer, the call to the first type of API is standardized and does not depend on the specific operating system. For example, for a request involving creating a new thread, the NCI core layer will call the thread creation API provided by the operating system abstraction layer.

[0057] After the processing request is passed to the operating system, the operating system will process the processing request according to its own mechanisms and rules. For example, the operating system may schedule a new thread to execute the specified task, or configure the hardware to prepare for data transmission.

[0058] After the operating system completes the processing, it returns the result to the operating system abstraction layer, and then the calling operating system abstraction layer converts these results into a unified format and feeds them back to the NCI core layer. Finally, the NCI core layer informs the original NFC application that initiated the request of the processing result.

[0059] In the embodiments of this application, the operating system abstraction layer effectively shields the differences between different operating systems, provides a unified interface for the NCI core layer to use, and greatly improves the portability of the code and the development efficiency. This enables users to focus on the implementation of the business logic without worrying about the compatibility issues of the underlying operating systems.

[0060] In a specific application example, such as Figure 3 shown, the operating system abstraction layer includes the operating system abstraction layer API and the operating system abstraction layer implementation (Impl).

[0061] The OSAL API is a set of standardized interfaces provided by the operating system abstraction layer. The interfaces allow high-level applications or protocol stacks to access the underlying services in an operating system-independent manner. Specifically, it includes the following modules: the OSI (Operating System Interface) module, which provides basic interfaces for interacting with the operating system, such as thread management, memory allocation, etc. The Transport module is responsible for operations related to data transmission, such as network communication, device drivers, etc. The LOG module is used to provide a logging function for debugging and monitoring system behavior. The Config module is used to provide a configuration management function, allowing application programs to read and modify configuration information. The Utils module is used to provide some general utility functions, such as string processing, timestamp operations, etc.

[0062] The operating system abstraction layer Impl is the specific implementation of the operating system abstraction layer, which provides corresponding implementation details for different operating systems. Specifically, it includes the following implementations: Android Impl, which is the specific implementation for the Android operating system. OHOS Impl is the specific implementation for the HarmonyOS (OHOS) operating system. Linux Impl is the specific implementation for the Linux operating system. RTOS Impl is the specific implementation for the real-time operating system (RTOS).

[0063] Specifically, in combination with Figure 3 , the data communication process between the CNI core layer and the operating system abstraction layer is introduced.

[0064] The NCI core layer calls the first type of API of the operating system abstraction layer. Specifically, when the NCI core layer needs to execute a certain operating system-related task, the NCI core layer will call the corresponding interface in the API of the operating system abstraction layer. For example, if a new thread needs to be created, the NCI core layer will call the thread management interface in the operating system abstraction layer API.

[0065] The operating system abstraction layer API calls the specific operating system abstraction layer Impl. Specifically, after receiving a processing request, the operating system abstraction layer API will select an appropriate operating system abstraction layer Impl according to the currently running operating system to perform specific tasks. For example, if it is running on the Android system, then the operating system abstraction layer API will call the relevant implementation in the Android Impl.

[0066] The Impl of the operating system abstraction layer executes the task and returns the result. Specifically, the operating system abstraction layer Impl executes the task according to the specific operating system characteristics and returns the result to the API of the operating system abstraction layer. For example, the Android Impl will use the API of the Android system to create a new thread and return the result to the operating system abstraction layer API.

[0067] The operating system abstraction layer API returns the result to the CNI core layer. Specifically, the operating system abstraction layer API converts the result obtained from the operating system abstraction layer Impl into a unified format and returns it to the CNI core layer.

[0068] In the embodiment of the present application, the operating system abstraction layer effectively shields the differences between different operating systems, enabling the same core layer to run on different operating systems. This improves the portability of the code, allowing the underlying operating system to be replaced as needed without affecting the upper-layer logic. The implementation related to each operating system is isolated in a separate module, facilitating maintenance and update.

[0069] Based on the above embodiment, the embodiment of the present application further optimizes the CNI protocol stack. Specifically, as Figure 4 shown, the NCI protocol stack further includes: an NFC service abstraction layer 14. The NFC service abstraction layer includes a plurality of second-class APIs, and the plurality of second-class APIs are abstracted from the APIs of the NCI core layer.

[0070] The NFC service abstraction layer is located above the NCI core layer and provides a set of higher-level second-class APIs. The second-class APIs are further abstracted based on the APIs provided by the NCI core layer. The NFC service abstraction layer itself does not handle any NFC protocol-related logic. The main task of the NFC service abstraction layer is to perform an adaptation layer to ensure that high-level NFC applications can access the functions of the core layer through a unified interface. Therefore, the code volume of the NFC service abstraction layer is relatively small, mainly for interface conversion and encapsulation work.

[0071] The second type of API refers to wrapping the underlying APIs provided by the CNI core layer into high-level APIs suitable for use by the upper-layer system's NFC service. The second type of API provides a more user-friendly interface, enabling users to more easily utilize NFC technology without delving into the specific details of the NCI protocol.

[0072] The second type of API is abstracted from the APIs of the NCI core layer, indicating that the second type of API provided by the NFC service abstraction layer does not directly send processing requests to the NCI core layer but is implemented through further encapsulation and abstraction of the APIs of the NCI core layer. For example, if an application wants to read information on an NFC tag, it only needs to call the corresponding API in the NFC service abstraction layer without caring about how the NCI core layer processes the data.

[0073] In the embodiments of this application, the NFC function can be quickly integrated by calling the high-level second type of API without the need to understand the specific details of the underlying protocol. If the underlying NCI protocol changes, only the adaptation part between the NFC service abstraction layer and the NCI core layer needs to be updated, without affecting the application programs using these services. Different NFC application scenarios can be supported by defining different service APIs, enabling the same set of systems to be reused in multiple different types of NFC applications.

[0074] As Figure 4 shown, the NCI core layer 11 is the core part of the entire protocol stack, responsible for handling the core logic and protocols of NFC communication, and its specific description can refer to the description in the above embodiments.

[0075] The NFC service abstraction layer provides an abstraction of the core layer APIs, enabling upper-layer applications to more conveniently access the NCI core layer. Among them, the NFC service abstraction layer 14 includes: an Android module, which provides an abstract interface for the Android system, enabling developers to use a unified API to access the NFC function on different Android devices. The OHOS module provides an abstract interface for the HarmonyOS (OpenHarmony) operating system, enabling developers to use a unified API to access the NFC function in the HarmonyOS. The Linux module provides an abstract interface for the Linux system, enabling developers to use a unified API to access the NFC function in a Linux environment. The RTOS provides an abstract interface for real-time operating systems, enabling developers to use a unified API to access the NFC function in embedded devices.

[0076] In addition, the NFC service abstraction layer interacts with the NFC service, which is implemented through the service code 15 of the host operating system. Specifically, the service code 15 of the host operating system contains specific implementations and services on different operating systems, including but not limited to: The NFC service is the NFC service component in the Android system, responsible for handling NFC-related operations and communicating with the hardware through the NFC Controller Interface (NCI). The OHOS NFC service is the NFC service component in the HarmonyOS (OpenHarmony), responsible for handling NFC-related operations and providing APIs for application programs to call. The Linux Client is a client application or service running on the Linux system. It may be a user space program for interacting with the NFC hardware. The RTOS is the NFC service component in the Real-Time Operating System. It is usually used in embedded devices to provide real-time response capabilities.

[0077] In a possible implementation, different second-class APIs correspond to different operating systems running the NFC application; any one of the second-class APIs in the NFC service abstraction layer generates a processing request for the NFC application in response to a call request from the NFC application and sends it to the NCI core layer.

[0078] The second-class API refers to a set of interfaces in the NFC service abstraction layer, mainly responsible for converting the requests of the NFC application into commands that can be understood and executed by the NCI core layer.

[0079] Different operating systems have different programming models and API styles. The purpose of the second-class API is to provide a unified interface so that the NFC application can run on different operating systems without a large amount of adaptation work. Each operating system corresponds to a specific set of second-class APIs.

[0080] When the NFC application needs to perform certain operations (such as reading tag information or emulating a card), it initiates a request by calling the second-class API. After receiving the request, the second-class API converts it into a format that the NFC controller can understand. The processing request generated by the second-class API is sent to the NCI core layer. The NCI is a standardized interface for defining the communication protocol between the host device and the NFC controller. Through the NCI core layer, the processing request can be accurately conveyed to the NFC controller and the corresponding hardware operation is executed by it.

[0081] Exemplarily, an NFC application wants to read the information of an NFC tag. The application will call the corresponding second - type API according to the currently running operating system. After receiving the request, the corresponding second - type API first parses the request content, and then constructs a data packet that conforms to the NCI specification based on the specific requirements of the request. After completing the construction of the request, the second - type API forwards this request to the NCI core layer. The NCI core layer, as an intermediary, ensures that the request can be delivered to the operating system in the correct format and protocol.

[0082] In the embodiments of this application, not only the tasks of NFC application developers are simplified, but also the flexibility and scalability of the system are enhanced, because the support for the new operating system can be achieved by adding the corresponding second - type API without modifying the underlying NCI core layer or the firmware of the NFC controller.

[0083] In a specific implementation, when the operating system on which the NFC application runs belongs to the first - type operating system, the first - type API includes the Java Native Interface; when the operating system on which the NFC application runs belongs to the second - type operating system, the first - type API includes the native method Native Interface.

[0084] Among them, the first - type operating system can be the Android system, and the second - type operating system can be the HarmonyOS.

[0085] When the NFC application runs on the first - type operating system, the first - type API includes the Java Native Interface. This indicates that the NFC application is written in Java and calls the underlying native code through JNI, and these native codes provide access to the NFC service abstraction layer.

[0086] In this case, the NFC application is developed using the Java language and uses the JNI mechanism to bridge the Java code and the underlying native library. This enables developers to enjoy the convenience brought by the Java language while also being able to utilize efficient native code to handle complex hardware operations.

[0087] Since Java is a high - level language with rich standard library support and good cross - platform characteristics; at the same time, through JNI, the functions of the underlying hardware can be fully utilized.

[0088] When the NFC application runs on the second - type operating system, the first - type API includes the native method interface. This means that the NFC application may be directly written in native languages such as C / C++ without an additional virtual machine layer. In this scenario, the NFC application can directly call the native API provided by the operating system or directly communicate with the NFC service abstraction layer without using a bridging technology like JNI. It usually involves directly handling underlying resources such as memory, threads, and file systems.

[0089] Due to the lack of an intermediate layer such as the Java virtual machine, the application can achieve higher performance and more direct hardware control capabilities.

[0090] In a possible implementation, when the operating system running the NFC application is an operating system other than the first type of operating system and the second type of operating system, the method further includes: the NCI core layer generates a processing request in response to a call request of the NFC application.

[0091] When the NFC service framework is not pre-installed in other systems, the API provided by the NFC protocol stack can be directly called to implement the interaction with the NFC hardware. This can provide higher flexibility and control.

[0092] Directly calling the protocol stack API means bypassing the higher-level service abstraction layer usually provided by the operating system or middleware, and instead directly using the interfaces provided by the underlying NFC protocol stack for programming. This includes directly processing the NFC data exchange protocol (such as ISO / IEC 14443, etc.), frame formats, command sets, etc.

[0093] In a possible implementation, as Figure 5 shown, when the operating system running the NFC application is Android, the JNI mechanism is used to interact with the NSAL layer. NfcNci.apk calls libtmnci_nsal.so through JNI. When the operating system running the NFC application is OHOS, the dlopen dynamic link library method is used to interact with the NSAL layer. nfc_service.z.so calls libtmnci_nsal.z.so through dlopen. When the operating system running the NFC application is Linux, the socket is used to interact with the NSAL layer. libtmnci_nsal_cli.so calls tmsnci_nsal_svr through the socket. When the operating system running the NFC application is RTOS, the direct API call is used to interact with the NSAL layer. The API provided by the NSAL layer is directly called.

[0094] The solution provided in the embodiments of the present application helps to improve the portability and maintainability of the system, enabling developers to use a unified interface to access the NFC function on different operating systems.

[0095] Figure 6This is a schematic structural diagram of a communication device based on a Near Field Communication (NFC) controller interface protocol stack in an embodiment of the present application. The NCI protocol stack includes an NCI core layer and an operating system abstraction layer. The operating system abstraction layer includes multiple first-type Application Programming Interfaces (APIs), and different first-type APIs correspond to different functions related to the operating system. For example, Figure 6 As shown, the communication device 60 based on the NFC controller interface protocol stack provided in the embodiment of the present application mainly includes: a first receiving module 61, configured to receive a processing request sent by an NFC application through the NCI core layer; a first sending module 62, configured to send the processing request to the operating system by invoking a first-type API corresponding to the data processing request in the operating system abstraction layer, so that the operating system processes the processing request.

[0096] In a possible implementation, the NCI protocol stack further includes an NFC service abstraction layer. The NFC service abstraction layer includes multiple second-type APIs, and the multiple second-type APIs are abstracted from the APIs of the NCI core layer.

[0097] In a possible implementation, different second-type APIs correspond to different operating systems for running NFC applications. The device further includes: a second sending module 62. Any one of the second-type APIs in the NFC service abstraction layer generates a processing request for the NFC application in response to a call request from the NFC application and sends it to the NCI core layer.

[0098] In a possible implementation, when the operating system for running the NFC application belongs to the first-type operating system, the first-type API includes a Java Native Interface; when the operating system for running the NFC application belongs to the second-type operating system, the first-type API includes a Native method Native Interface.

[0099] In a possible implementation, when the operating system for running the NFC application is an operating system other than the first-type operating system and the second-type operating system, the device further includes a processing request generation module, configured to generate a processing request in response to a call request from the NFC application by the NCI core layer.

[0100] In a possible implementation, the functions related to the operating system include at least one of the following: locks, threads, logging, input / output, and NCI instructions.

[0101] In a possible implementation, the development language in the NCI core layer is the C language.

[0102] The communication device based on the NFC controller interface protocol stack provided in the embodiment of the present application can execute the communication method based on the NFC controller interface protocol stack provided in any embodiment of the present invention, and has corresponding functional modules and beneficial effects for executing the method.

[0103] Figure 7 is a schematic structural diagram of an electronic device provided in this embodiment. The electronic device may include a communication device based on a near field communication controller interface protocol stack, such as Figure 7 As shown, the electronic device 700 includes a processor 710, a memory 720, an input device 730, and an output device 740; the number of processors 710 in the electronic device may be one or more, Figure 7 Taking one processor 710 as an example; the processor 710, the memory 720, the input device 730, and the output device 740 in the electronic device may be connected through a bus or other means, Figure 7 Taking connection through a bus as an example.

[0104] The memory 720, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as program instructions / modules corresponding to the communication method based on the near field communication controller interface protocol stack in the embodiments of the present invention. The processor 710 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 720, that is, implements the communication method based on the near field communication controller interface protocol stack provided in the embodiments of the present invention.

[0105] The memory 720 may mainly include a program storage area and a data storage area. Among them, the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 720 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some instances, the memory 720 may further include a memory remotely set relative to the processor 710, and these remote memories may be connected to the electronic device through a network. Examples of the above networks include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0106] The input device 730 can be used to receive input digital or character information, and generate key signal inputs related to the user settings and function controls of the electronic device, and may include a keyboard, a mouse, etc. The output device 740 may include a display device such as a display screen.

[0107] This embodiment also provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to implement the communication method based on the near field communication controller interface protocol stack provided in the embodiments of the present invention when executed by a computer processor.

[0108] Of course, the storage medium containing computer-executable instructions provided by the embodiments of the present invention is not limited to the above method operations, and can also execute related operations in the communication method based on the near field communication controller interface protocol stack provided by any embodiment of the present invention.

[0109] From the above description of the embodiments, those skilled in the art can clearly understand that the present invention can be implemented by means of software and necessary general-purpose hardware. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as a floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk, or optical disc of a computer, etc., including several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods of various embodiments of the present invention.

[0110] It should be noted that in the above embodiments of the communication device based on the near field communication controller interface protocol stack, the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of the functional units are only for the convenience of mutual distinction and do not limit the protection scope of the present invention.

[0111] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including an..." does not exclude the existence of another identical element in the process, method, article or device including the element.

[0112] The above are only specific embodiments of the present application, enabling those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments herein, but rather to the broadest scope consistent with the principles and novel features disclosed herein.

Claims

1. A communication method based on a near field communication controller interface protocol stack, characterized in that, The Near Field Communication Controller Interface NCI protocol stack includes: an NCI core layer and an operating system abstraction layer. The operating system abstraction layer includes multiple first-class application programming interfaces APIs, and different ones of the first-class APIs correspond to different functions related to the operating system; The method includes: Receiving, through the NCI core layer, a processing request sent by an NFC application; Sending the processing request to the operating system by calling a first-class API corresponding to the data processing request in the operating system abstraction layer, so that the operating system processes the processing request.

2. The method according to claim 1, wherein The NCI protocol stack further includes: an NFC service abstraction layer. The NFC service abstraction layer includes multiple second-class APIs, and the multiple second-class APIs are abstracted from the APIs of the NCI core layer.

3. The method according to claim 2, wherein Different ones of the second-class APIs correspond to different operating systems running the NFC application; The method further includes: Any one of the second-class APIs in the NFC service abstraction layer generates a processing request for the NFC application in response to a call request from the NFC application, and sends it to the NCI core layer.

4. The method according to claim 3, wherein When the operating system running the NFC application belongs to a first-class operating system, the first-class API includes a Java Native Interface; When the operating system running the NFC application belongs to a second-class operating system, the first-class API includes a Native Method Native Interface.

5. The method according to claim 3, characterized in that, When the operating system running the NFC application is an operating system other than the first-class operating system and the second-class operating system, the method further includes: The NCI core layer generates a processing request in response to a call request from the NFC application.

6. The method according to claim 1, wherein The functions related to the operating system include at least one of the following: locks, threads, logging, input / output, NCI instructions.

7. The method according to any one of claims 1-6, characterized in that, The development language of the NCI core layer is the C language.

8. A communication device based on a near-field communication controller interface protocol stack, characterized in that, The Near Field Communication Controller Interface NCI protocol stack includes: an NCI core layer and an operating system abstraction layer. The operating system abstraction layer includes multiple first-class application programming interfaces APIs, and different ones of the first-class APIs correspond to different functions related to the operating system; The device includes: A first receiving module, configured to receive, through the NCI core layer, a processing request sent by an NFC application; A first sending module, configured to send the processing request to the operating system by calling a first-class API corresponding to the data processing request in the operating system abstraction layer, so that the operating system processes the processing request.

9. An electronic device, characterized in that, The device includes: One or more processors; A storage device, configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the communication method based on the Near Field Communication Controller Interface protocol stack according to any one of claims 1-7.

10. A storage medium, on which a computer program is stored, characterized in that, When the program is executed by the processor, it implements the communication method based on the Near Field Communication Controller Interface protocol stack according to any one of claims 1-7.