# Dynamic Resolution of Protocol ID for 3rd Party API calls

**URL:** <https://forum.legato.io/t/dynamic-resolution-of-protocol-id-for-3rd-party-api-calls/6777>\
**Category:** Legato Application Framework\
**Created:** [August 26, 2024, 4:37pm UTC](https://forum.legato.io/t/dynamic-resolution-of-protocol-id-for-3rd-party-api-calls/6777 "2024-08-26T16:37:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)\
**Post date:** [August 26, 2024, 4:37pm UTC](https://forum.legato.io/t/dynamic-resolution-of-protocol-id-for-3rd-party-api-calls/6777/1 "2024-08-26T16:37:24Z")

</div>

We are attempting to port a Go application to the WP77 target. The use of custom compile tools (mkapp, etc.) complicates the use of `cgo`. To at least get something working I am leaning towards the approach shown in [a prior thread](https://forum.legato.io/t/how-does-a-3rd-party-go-golang-app-call-a-service/3325/17). In this thread, the Go code is able to interact with a legato defined API once the Protocol ID is resolved (all other information can be gathered prior to runtime).

If I am trying to interact with a [predefined service API](https://github.com/legatoproject/legato-af/blob/master/interfaces/modemServices/le_mdc.api) (unlike the prior thread that defines a new printer API), how can I resolve the Protocol ID and Name at runtime?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [August 26, 2024, 5:08pm UTC](https://forum.legato.io/t/dynamic-resolution-of-protocol-id-for-3rd-party-api-calls/6777/2 "2024-08-26T17:08:00Z")

</div>

maybe protocol ID can be found by the following:

```auto
root@swi-mdm9x28-wp:~# ls -l /mnt/flash/legato/systems/current/apps/ | grep hello
lrwxrwxrwx 1 root root 45 Jan 6 00:23 hello8 -> /legato/apps/9d41dd782ea4cecad3de6daa0dc74e55
root@swi-mdm9x28-wp:~# ls -l /legato/systems/current/apps/ | grep hello
lrwxrwxrwx 1 root root 45 Jan 6 00:23 hello8 -> /legato/apps/9d41dd782ea4cecad3de6daa0dc74e55

```

---

<div class="post-metadata">

**Author:** ![upsampled](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@upsampled](https://forum.legato.io/u/upsampled)\
**Post date:** [August 28, 2024, 5:26pm UTC](https://forum.legato.io/t/dynamic-resolution-of-protocol-id-for-3rd-party-api-calls/6777/3 "2024-08-28T17:26:31Z")

</div>

I have gotten `cgo` working so just going to go that route.

## Compile Commands

```auto
. /opt/swi/SWI9X06Y_03.00.13.00/environment-setup-armv7a-neon-poky-linux-gnueabi 
go generate ./
CC=$CC GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 go build ./legatoutil.go 
mkapp -w /tmp/pabuild -t wp77xx ./legatoutil.adef

```

## cgo Header

This needs to be in one file in the package calling legato libraries. It can probably also be cleaned up by using the LEGATO\_ROOT environment variable.

```auto
//go:generate ifgen --output-dir $PWD/ifgen --gen-interface --gen-common-interface --gen-client --gen-common-client --gen-local --gen-messages /var/wp77xx/yocto/legato/interfaces/modemServices/le_mdc.api
//go:generate bash -c "cd ./ifgen; $CC -c *.c -I/var/wp77xx/yocto/legato/framework/include -I/var/wp77xx/yocto/legato/build/wp77xx/framework/include; ar rcs libpalegato.a *.o"

/*
#cgo CFLAGS: -I/var/wp77xx/yocto/legato/framework/include -I/var/wp77xx/yocto/legato/build/wp77xx/framework/include -I${SRCDIR}/ifgen
#cgo LDFLAGS: -L/var/wp77xx/yocto/legato/build/wp77xx/framework/lib/ -llegato -L${SRCDIR}/ifgen -lpalegato
*/
import "C"

```

## adef file

```auto
// Disable the sandbox security to make things a little easier.
sandboxed: false

// Put the cross-compiled legacy program in the app's bin directory.
// [x] = make it executable.
bundles:
{
    file:
    {
        [x] $CURDIR/legatoutil /bin/legatoutil
    }
}
extern:
{
    requires:
    {
        le_mdc = $LEGATO_ROOT/interfaces/modemServices/le_mdc.api
    }
}
bindings:
{
     *.le_mdc -> modemService.le_mdc
}

```
