bbfdm/docs/guide/libbbfdm-api_obj_param_extension.md
2024-06-12 11:17:30 +02:00

8.4 KiB

How to add support for a new Object/Parameter

As mentioned in README, all Data Models are stored in the 'dmtree' folder. In order to implement a new object/parameter, you need to expand its get/set/add/delete functions and then save them in the right folder.

bbfdm library offers a tool to generate templates of the source code from json files placed under 'dmtree/json'. So, any developer can fill the data model json file data_model with mapping field according to UCI, UBUS or CLI commands then generate the source code in C.

$ ./convert_dm_json_to_c.py    
Usage: ./tools/convert_dm_json_to_c.py [Object path]
Examples:
  - ./tools/convert_dm_json_to_c.py
    ==> Generate the C code of full data model in datamodel/ folder
  - ./tools/convert_dm_json_to_c.py Device.DeviceInfo.
    ==> Generate the C code of Device.DeviceInfo object in datamodel/ folder

Below some examples of UCI, UBUS or CLI mappings:

UCI command

  • @Name: the section name of parent object

  • @i: is the number of instance object

	"mapping": [
		{
			"type": "uci",
			"uci": {
				"file": "wireless",
				"section": {
					"type": "wifi-device",
					"name": "@Name",
					"index": "@i-1"
				},
				"option": {
					"name": "disabled"
				}
			}
		}
	]

UBUS command

  • @Name: the section name of parent object
	"mapping": [
		{
			"type": "ubus",
			"ubus": {
				"object": "network.device",
				"method": "status",
				"args": {
					"name": "@Name"
				},
				"key": "statistics.rx_bytes"
			}
		}
	]

CLI command:

  • @Name: the section name of parent object

  • -i: is the number of arguments command

	"mapping": [
		{
			"type" : "cli",
			"cli" : {
				"command" : "wlctl",
				"args" : [
					"-i",
					"@Name",
					"bands"
				]
			}
		}
	]

After building the templates of C source code, a datamodel folder will be generated under 'tools' folder that contains all files related to each object under root "Device."

Note: You can generate the source code without filling out the mapping field in the JSON file

Object definition

Each object in the DMOBJ table contains the following arguments:

Argument Description
OBJ A string of the object name. Example “Bridging”, “IP”, “DeviceInfo”, “WiFi”
permission The permission of the object. Could be &DMREAD or &DMWRITE. If it's &DMWRITE then we can add/delete instances of this object
addobj The function to add new instance under this object. This function will be triggered when the ACS/Controller call AddObject of this object
delobj The function to delete instance under this object. This function will be triggered when the ACS/Controller call DeleteObject of an instance of this object
checkdep A string of the object dependency, it can be a file("file:/etc/config/network") or an ubus object,method("ubus:network.interface->status"). If it's NULL then the object has always appeared in the tree
browseinstobj This function allow to browse all instances under this object
nextdynamicobj Pointer to the next of DMOBJ which contains a list of the child objects using json files, shared libraries and vendor extension
dynamicleaf Pointer to the next of DMLEAF which contains a list of the child parameters using json files, shared libraries and vendor extension
nextobj Pointer to a DMOBJ array which contains a list of the child objects
leaf Pointer to a DMLEAF array which contains a list of the child parameters
linker This argument is deprecated and should be NULL
bbfdm_type The bbfdm type of the object. Could be BBFDM_CWMP, BBFDM_USP, BBFDM_BOTH or BBFDM_NONE.If it's BBFDM_BOTH then we can see this object in all protocols (CWMP, USP,...)
uniqueKeys This argument is deprecated and should be NULL

Leaf definition

Each leaf in the DMLEAF table can be a Parameter, Command or Event.

1.Parameter definition

Argument Description
PARAM A string of the parameter name. Example “Enable”, “Status”, “Name”
permission The permission of the parameter. Could be &DMREAD or &DMWRITE.If it's &DMWRITE then we can set a value for this parameter
type Type of the parameter: DM_STRING, DM_BOOL, DM_UNINT,...
getvalue The function which return the value of this parameter
setvalue The function which set the value of this parameter
bbfdm_type The bbfdm type of the parameter. Could be BBFDM_CWMP, BBFDM_USP, BBFDM_BOTH or BBFDM_NONE.If it's BBFDM_BOTH then we can see this parameter in all protocols (CWMP, USP,...)
dm_falgs An enumeration value used to specify the displayed parameter value. Could be DM_FLAG_REFERENCE, DM_FLAG_UNIQUE, DM_FLAG_LINKER or DM_FLAG_SECURE.

2.Command definition

Argument Description
PARAM A string of the command name. Example “IPPing()”, “DownloadDiagnostics()”, “Renew()”
permission The permission of the command. Could be &DMASYNC or &DMSYNC.
type Type of the command, It should be DMT_COMMAND
getvalue The function which return the input, output arguments of the command
setvalue The function which call the operation of the command
bbfdm_type The bbfdm type of the command. It should be BBFDM_USP as long as operate commands are only defined in USP protocol.

3.Event definition

Argument Description
PARAM A string of the event name. Example “Boot!”, “Push!”, “Periodic!”
permission The permission of the event. It should be DMREAD
type Type of the event, It should be DMT_EVENT
getvalue The function which return the parameter arguments of the event
setvalue The function which call the operation of the event
bbfdm_type The bbfdm type of the event. It should be BBFDM_USP as long as events are only defined in USP protocol.

Browse definition

The browse function allow to go over all instances of the current object and link them to the data model tree.

In this function, there are two functions that need to be defined:

  • function to retrieve the instances: it can be:

    • handle_instance function: allow to retrieve/attribute the instances number/alias from uci config sections depending of the request and the instance mode.

    • handle_instance_without_section function: allow to attribute the instances number/alias with constant values.

  • function to link the instances: To link each instance to the data model tree, it's necessary to call DM_LINK_INST_OBJ() API for every instance. Additionally, it's mandatory to use the generic structure (struct dm_data *) as passed data at each instance level in order to maintain the capability to extend the data model using JSON plugin. This structure will be utilized later in functions related to sub-objects and parameters (Get/Set/Add/Delete/Operate/Event).

Note1: the browse function is only developed for multi-instances objects.

Note2: you can use bbf_test plugin as a reference in order to develop any new object/leaf/browse.